package com.gan.bi.manager;

import com.gan.bi.common.ErrorCode;
import com.gan.bi.exception.BusinessException;
import com.gan.bi.exception.ThrowUtils;
import com.yupi.yucongming.dev.client.YuCongMingClient;
import com.yupi.yucongming.dev.common.BaseResponse;
import com.yupi.yucongming.dev.model.DevChatRequest;
import com.yupi.yucongming.dev.model.DevChatResponse;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author gbw
 * @date 2023/7/17
 */
@Service
@Slf4j
public class AiManager {

    @Resource
    private YuCongMingClient yuCongMingClient;

    /**
     * 调用接口与 AI 对话
     * @param modelId
     * @param message
     * @return
     */
    public String doChat(long modelId,String message){
        DevChatRequest devChatRequest = new DevChatRequest();
        // 模型 ID
        devChatRequest.setModelId(modelId);
        devChatRequest.setMessage(message);

        BaseResponse<DevChatResponse> response = yuCongMingClient.doChat(devChatRequest);
//        log.info("response" + response);
        ThrowUtils.throwIf(response == null || response.getData() == null,new BusinessException(ErrorCode.OPERATION_ERROR,"ai 无响应..."));
        return response.getData().getContent();
    }
}
